package com.rongcheng.fortestlist;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.rongcheng.fortestlist.model.MainListModel;

import java.util.ArrayList;
import java.util.List;

/**
 * @author frc
 *         created at 16-12-20.
 */

public class MainRecyclerViewAdapter extends BaseRecyclerViewAdapter {
    private LayoutInflater layoutInflater;
    private Context mContext;
    private List<MainListModel> mList = new ArrayList<>();

    public MainRecyclerViewAdapter(Context context) {
        this.mContext = context;
        layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public void update(List<MainListModel> listModels) {
        this.mList = listModels;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
        final View itemView = layoutInflater.inflate(R.layout.item_main_recycler_view, parent, false);
        return new MainRecyclerViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onRecyclerViewItemClickListener.onRecyclerViewItemClick(holder.itemView, position);
            }
        });
        ((AbstractViewHolder) holder).bindData(mList.get(position));
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }
}
